﻿using Sirius.SystemDll;

using static Sirius.Log.Log;
namespace Sirius.Application
{
    public class Application
    {
        //应用实例
        public FileInfo fileInfo;

        //应用内存地址
        public  IntPtr instance;
        
        //存储应用函数
        public readonly ApplicationMethod Method;

        //应用数据目录
        public string DataPath;

        //应用目录
        public string AppPath;

        //应用信息
        public ApplicationInfo appInfo;
        
        public Application(FileInfo AppFile)
        {
            try
            {
                
                AppPath = AppFile.FullName;
                instance = kernel32.LoadLibraryA(AppPath);



                if (instance != null)
                    Method = ApplicationMethod.CreateMethod(instance);

                DataPath = $"{AppDomain.CurrentDomain.SetupInformation.ApplicationBase}" + @"Data\Plugin\" + Path.GetFileNameWithoutExtension(AppFile.Name);
                appInfo = Method.getAppInfo(DataPath);



                //判断数据目录是否存在
                if (!Directory.Exists(DataPath))
                    Directory.CreateDirectory(DataPath);
                
            }
            catch (Exception ex)
            {
                LogErr("Server", "应用初始化失败！" + ex.Message);
            }
        }
        public void Dispose()
        {
            kernel32.FreeLibrary(instance); 
        }
            
    }
}
